package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.Subscribe;
import com.ruoyi.project.system.service.ISubscribeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 订阅Controller
 * 
 * @author ruoyi
 * @date 2021-05-18
 */
@RestController
@RequestMapping("/system/subscribe")
public class SubscribeController extends BaseController
{
    @Autowired
    private ISubscribeService subscribeService;

    /**
     * 查询订阅列表
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:list')")
    @GetMapping("/list")
    public TableDataInfo list(Subscribe subscribe)
    {
        startPage();
        List<Subscribe> list = subscribeService.selectSubscribeList(subscribe);
        return getDataTable(list);
    }

    /**
     * 导出订阅列表
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:export')")
    @Log(title = "订阅", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Subscribe subscribe)
    {
        List<Subscribe> list = subscribeService.selectSubscribeList(subscribe);
        ExcelUtil<Subscribe> util = new ExcelUtil<Subscribe>(Subscribe.class);
        return util.exportExcel(list, "订阅数据");
    }

    /**
     * 获取订阅详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(subscribeService.selectSubscribeById(id));
    }

    /**
     * 新增订阅
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:add')")
    @Log(title = "订阅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Subscribe subscribe)
    {
        return toAjax(subscribeService.insertSubscribe(subscribe));
    }

    /**
     * 修改订阅
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:edit')")
    @Log(title = "订阅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Subscribe subscribe)
    {
        return toAjax(subscribeService.updateSubscribe(subscribe));
    }

    /**
     * 删除订阅
     */
    @PreAuthorize("@ss.hasPermi('system:subscribe:remove')")
    @Log(title = "订阅", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(subscribeService.deleteSubscribeByIds(ids));
    }
}
